﻿using CloudDcPc.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CloudDcPc.FuckDlg
{
    /// <summary>
    /// TabEditDlg.xaml 的交互逻辑
    /// </summary>
    public partial class TabEditDlg : Window
    {
        Tab tab = null;
        public TabEditDlg(Tab tab)
        {
            InitializeComponent();
            this.tab = tab;
            main_grid.DataContext = tab;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                Int32.Parse(txt_tab_num.Text);
                Int32.Parse(txt_size.Text);
            }
            catch
            {
                MessageBox.Show("桌号或人数填写错误，只能是数字！");
                return;
            }

            if (txt_name.Text == "")
            {
                MessageBox.Show("名称不能为空！");
                return;
            }

            BindingExpression bind = txt_tab_num.GetBindingExpression(TextBox.TextProperty);
            bind.UpdateSource();
            bind = txt_name.GetBindingExpression(TextBox.TextProperty);
            bind.UpdateSource();
            bind = txt_size.GetBindingExpression(TextBox.TextProperty);
            bind.UpdateSource();
            bind = cb_status.GetBindingExpression(ComboBox.TextProperty);
            bind.UpdateSource();
            bind = cb_wait.GetBindingExpression(ComboBox.TextProperty);
            bind.UpdateSource();
            if (App.TabBean.UpdateTab(tab))
            {
                MessageBox.Show("更新成功！");
                this.Close();
            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            string messageBoxText = "确认删除该桌位吗？";
            string caption = "删除桌位";
            MessageBoxButton button = MessageBoxButton.YesNo;
            MessageBoxImage icon = MessageBoxImage.Warning;
            MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
            if (result == MessageBoxResult.Yes)
            {
                if (App.TabBean.DelTabById(tab.Id))
                {
                    MessageBox.Show("删除成功！");
                    this.DialogResult = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
